import win32gui
import uiautomation


def get_window():
    hwnd = win32gui.FindWindow("TrayNotifyWnd", "微信")
    if hwnd == 0:
        raise Exception("未检测到微信进程！")
    window = uiautomation.WindowControl(searchDepth=1, Name="微信", ClassName='WeChatMainWndForPC')
    window.SetActive()
    window.SetTopmost()
    return window


def get_chat_list_panel(window):
    return window.ListControl(name='会话')


def get_one_session_new_msg_button(window):
    children = \
        window.GetChildren()[1].GetChildren()[0].GetChildren()[2].GetChildren()[0].GetChildren()[0].GetChildren()[
            0].GetChildren()[0].GetChildren()[1].GetChildren()[0].GetChildren()[0].GetChildren()
    if len(children) > 1:
        return children[1].GetChildren()[0].GetChildren()[0].GetChildren()[1]
    return None
